#coding:utf-8
__author__ = 'nhsheng'

import logging.config
from datetime import datetime
import logging
import os

import yaml

import readConfig

'''初始化日志'''
def logger():
    global  logPath,resultPaht,proDir,logConfigPath
    proDir= readConfig.proDir
    resultPaht=os.path.join(proDir,"logs")
    if not os.path.exists(resultPaht):
        os.mkdir(resultPaht)
    logPath=os.path.join(resultPaht,datetime.now().strftime("%Y%m%d"))
    if not os.path.exists(logPath):
        os.mkdir(logPath)
    logConfigPath=os.path.join(proDir,"logging.yaml")
    if os.path.exists(logConfigPath):
        with open(logConfigPath,"r") as f:
            data=yaml.load(f)
            data['handlers']['info_file_handler']['filename']=os.path.join(logPath,"info.log")
            data['handlers']['error_file_handler']['filename']=os.path.join(logPath,"error.log")
            logging.config.dictConfig(data)
            logger=logging.getLogger(__name__)
            f.close()
            return logger
